package com.ruoyi.system.api.factory;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.system.api.BasicService;
import com.ruoyi.system.api.DetectService;
import com.ruoyi.system.api.domain.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;

@Component
public class DetectServiceFallbackFactory implements FallbackFactory<DetectService> {

    private static final Logger log = LoggerFactory.getLogger(DetectServiceFallbackFactory.class);
    @Override
    public DetectService create(Throwable throwable)
    {
        log.error("基础服务调用失败:{}", throwable.getMessage());
        return new DetectService()
        {
            @Override
            public TableDataInfo selectQcDefectRecord(Long qc_id) {
                log.error("获取查询缺陷记录信息失败:{}", throwable.getMessage());
                return new TableDataInfo();
            }

            @Override
            public TableDataInfo selectQcIpqcLineId(Long ipqcId)
            {
                log.error("获取过程检测单行记录信息失败:{}", throwable.getMessage());
                return new TableDataInfo();
            }

            @Override
            public QcIpqcDto selectQcIpqcId(Long qc_id)
            {
                log.error("获取过程检测单信息失败:{}", throwable.getMessage());
                return new QcIpqcDto();
            }

            @Override
            public QcIqcDto selectQcIqcId(Long source_doc_id) {
                return new QcIqcDto();
            }

            @Override
            public QcOqcDto selectQcOqcListSourceDocId(Long source_doc_code) {
                return new QcOqcDto();
            }

            @Override
            public QcRqcDto selectQcRqcListSourceDocId(Long source_doc_code) {
                return new QcRqcDto();
            }

            @Override
            public AjaxResult add(QcIpqcDto qcIpqcDto) {
                log.error("质检服务不可用，创建过程检验单失败:{}", throwable.getMessage());
                return AjaxResult.error("质检服务不可用，创建过程检验单失败");
            }

            @Override
            public AjaxResult add(QcRqcDto qcRqcDto) {
                log.error("质检服务不可用，创建退料检验单失败:{}", throwable.getMessage());
                return AjaxResult.error("质检服务不可用，创建退料检验单失败");
            }

            @Override
            public QcTemplateProductDto selectQcTemplateProductMaterialCode(String material_code) {
                log.error("质检服务不可用，查询物料检测方案失败:{}", throwable.getMessage());
                return null; // 返回null表示未找到检测方案，业务逻辑会跳过质检
            }

            @Override
            public QcTemplateProductDto selectQcTemplateProductProductCode(Long product_id) {
                log.error("质检服务不可用，查询产品检测方案失败:{}", throwable.getMessage());
                return null; // 返回null表示未找到检测方案，业务逻辑会跳过质检
            }
        };
    }
}
